package com.albert.activitystreamdemo.config;

import org.activiti.engine.*;
import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @auther cyq
 * @create 11:40 2021/3/2
 */
@Configuration
public class ActivitiConfig {
    @Autowired

    private DataSource dataSource;

    /**
     * 初始化配置，将创建25张表
     *
     * @return
     */
    @Bean
    public StandaloneProcessEngineConfiguration processEngineConfiguration() {
        StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
        configuration.setDataSource(dataSource);
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        /* 定义为true，使用AsyncExecutor代替默认的JobExecutor;*/
        configuration.setAsyncExecutorActivate(true);
        configuration.setAsyncExecutorActivate(true);
        return configuration;
    }

    /**
     * 创建引擎
     *
     * @return ProcessEngine
     */
    @Bean
    public ProcessEngine processEngine() {
        return processEngineConfiguration().buildProcessEngine();
    }
    @Bean
    public RepositoryService repositoryService() {
        return processEngine().getRepositoryService();
    }

    @Bean
    public RuntimeService runtimeService() {
        return processEngine().getRuntimeService();
    }

    @Bean
    public TaskService taskService() {
        return processEngine().getTaskService();
    }
    @Bean
    public HistoryService historyService() {
        return processEngine().getHistoryService();
    }
    @Bean
    public ManagementService  managementService() {
        return processEngine().getManagementService();
    }


}

